** QWI, Nielsen store types, labor market effects of MW
** JHL

*************************************
** Set up workspace
*************************************
version 14.0
clear all
set more off

cd "${path_home}"
adopath + ../programs

cap ssc install estout
cap ssc install parmest
cap ssc install reghdfe
cap ssc install eclplot
cap ssc install blindschemes, replace all

** log using "${path_log}/a02_qwi_mw_labor_mkt_effects", text replace

*************************************
** Start work here
*************************************
timer on 1

use "${path_big_dta}/qwi/qwi_all_sa_f_gc_n4_op_u_ns_mw_0615", clear

** Contiguous US only 
keep if state != 2 & state != 15

*************************************
** [1] Regressions, parallelize or in forloop
*************************************

** Paper table: Industry, county and time FE, log earnings and employment 
foreach v of varlist log_earnb log_emp {
	foreach i in 4451 4461 4521 4529 7225 {
		fixed_effects if industry==`i', y(`v') x(log_mwq) panel(panelvar) ///
		unit(geography) year(year) period(quarter) opt(contemp cumul) ///
		controls(logpop) ///
		cluster(state) lags(4) leads(6) addleads time(yq) fe(3)  savereg(, name(ctfe_`i'_0615_all_counties) dir(${path_out}/reg/)) ///
		outgraphs(, dir(${path_out}/graphs/) num(1))
	} 
}

** Appendix table: Industry, county and time FE, log earnings and employment, above/below Kaitz median 
foreach v of varlist log_earnb log_emp {
	foreach i in 4451 4461 4521 4529 7225 {
		foreach q of numlist 1/2 {
			fixed_effects if industry==`i'&year>=2006&year<=2015 & state != 2 & state != 15 & kaitz_y2006_qtr1_q2_c == `q', ///
			y(`v') x(log_mwq) controls(logpop) ///
			unit(geography) year(year) period(quarter) opt(contemp) ///
			cluster(state) lags(4) leads(6) addleads panel(panelvar) time(yq) fe(3) ///
			savereg(, name(ctfe_`i'_0615_all_counties_h`q') dir(${path_out}/reg/)) ///
			outgraphs(, dir(${path_out}/graphs/) num(1))
		}
	} 
}

*************************************
** Close workspace
*************************************
timer off 1
timer list 1
** log close